import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        hasRoutes: false, // 是否为第一次加载路由
        menuList: [],
        authList: [],
        editableTabsValue: 'Index',
        editableTabs: [
            {
                title: '首页',
                name: 'Index',
            }
        ]
    },
    getters: {},
    mutations: {
        // 设置菜单列表
        SET_MENU_LIST(state, menuList) {
            state.menuList = menuList;
        },
        // 设置权限列表
        SET_AUTH_LIST(state, authList) {
            state.authList = authList;
        },
        // 设置路由已经加载过
        SET_HAS_ROUTES(state, hasRoutes) {
            state.hasRoutes = hasRoutes;
        },
        ADD_TAB(state, tab) {
            // 查看要添加的标签是否已经存在
            let index = state.editableTabs.findIndex(e => e.name === tab.name);
            console.log(tab.name)

            // 没有找打 不存在 则添加
            if (index === -1) {
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name,
                })
            }
            // 把标签名字改为刚添加的名字
            state.editableTabsValue = tab.name;
        },
        RESET_TAB_STATUS(state) {
            state.menuList = [];
            state.authList = [];
            state.hasRoutes = false;
            state.editableTabsValue = 'Index';
            state.editableTabs = [
                {
                    title: '首页',
                    name: 'Index',
                }
            ]
        }
    },
    actions: {}
}
